package com.atguigu.cloud.service.impl;

import com.atguigu.cloud.entities.Pay;
import com.atguigu.cloud.mapper.PayMapper;
import com.atguigu.cloud.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
public class PayServiceImpl implements PayService {
    @Autowired
    private PayMapper payMapper;

    @Override
    public int add(Pay pay) {
        return payMapper.insert(pay);
    }

    @Override
    public Integer delete(Integer id) {
        return payMapper.deleteById(id);
    }

    @Override
    public int update(Pay pay) {
        return payMapper.updateById(pay);
    }

    @Override
    public Pay getById(Integer id) {
        return payMapper.selectById(id);
    }

    @Override
    public List<Pay> getAll() {
        return Optional.ofNullable(payMapper.selectList(null)).orElse(new ArrayList<>());
    }
}
